<!DOCTYPE html>












  


<html class="theme-next gemini use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2"/>
<meta name="theme-color" content="#222">






  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />










  <meta name="baidu-site-verification" content="code-ko3Wygxh1F" />













<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=6.5.0" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/wolf_128.png?v=6.5.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/wolf_32.png?v=6.5.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/wolf_16.png?v=6.5.0">


  <link rel="mask-icon" href="/images/wolf.svg?v=6.5.0" color="#222">









<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '6.5.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":true},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="Freemarker学习[toc]  注意点： 1、Freemarker得注释是&lt;#–注释的内容–&gt; 2、Freemarker的标签必须完整，否则报错、失效  一、如何显示数据语法1234567891011$&amp;#123;num&amp;#125;  # num八大基础类型$&amp;#123;emp.name&amp;#125;  # obj是对象，并且要满足javaBean的规范，以及该类要以public修">
<meta property="og:type" content="article">
<meta property="og:title" content="Freemarker学习">
<meta property="og:url" content="https://chaasuc.github.io/2021/03/05/Freemarker%E5%AD%A6%E4%B9%A0/index.html">
<meta property="og:site_name" content="Deschen Blog">
<meta property="og:description" content="Freemarker学习[toc]  注意点： 1、Freemarker得注释是&lt;#–注释的内容–&gt; 2、Freemarker的标签必须完整，否则报错、失效  一、如何显示数据语法1234567891011$&amp;#123;num&amp;#125;  # num八大基础类型$&amp;#123;emp.name&amp;#125;  # obj是对象，并且要满足javaBean的规范，以及该类要以public修">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-03-05T10:42:58.000Z">
<meta property="article:modified_time" content="2021-03-17T16:29:59.183Z">
<meta property="article:author" content="Deschen">
<meta property="article:tag" content="Freemarker">
<meta name="twitter:card" content="summary">



  <link rel="alternate" href="/atom.xml" title="Deschen Blog" type="application/atom+xml" />




  <link rel="canonical" href="https://chaasuc.github.io/2021/03/05/Freemarker学习/"/>



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>Freemarker学习 | Deschen Blog</title>
  











  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

<meta name="generator" content="Hexo 4.2.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Deschen Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <p class="site-subtitle">以Java开发为主的个人博客，记录自己在学习、工作和成长的笔记和心得</p>
      
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">
    <a href="/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-about">
    <a href="/about/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">
    <a href="/tags/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />标签<span class="badge">36</span></a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">
    <a href="/categories/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-th"></i> <br />分类<span class="badge">19</span></a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">
    <a href="/archives/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档<span class="badge">67</span></a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-sitemap">
    <a href="/sitemap.xml" rel="section">
      <i class="menu-item-icon fa fa-fw fa-sitemap"></i> <br />站点地图</a>
  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />搜索</a>
        </li>
      
    </ul>
  

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



  



</div>
    </header>

    
  
  
  
    
      
    
    <a href="https://github.com/ChaASuc" class="github-corner" target="_blank" title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#222; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg>
    
      </a>
    



    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://chaasuc.github.io/2021/03/05/Freemarker%E5%AD%A6%E4%B9%A0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Deschen">
      <meta itemprop="description" content="机遇只会给有准备的人">
      <meta itemprop="image" content="/images/wolf_128.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Deschen Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Freemarker学习
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2021-03-05 18:42:58" itemprop="dateCreated datePublished" datetime="2021-03-05T18:42:58+08:00">2021-03-05</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2021-03-18 00:29:59" itemprop="dateModified" datetime="2021-03-18T00:29:59+08:00">2021-03-18</time>
              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/%E6%A8%A1%E6%9D%BF%E5%BC%95%E6%93%8E/" itemprop="url" rel="index"><span itemprop="name">模板引擎</span></a></span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2021/03/05/Freemarker%E5%AD%A6%E4%B9%A0/#comments" itemprop="discussionUrl">
                  <span class="post-meta-item-text">评论数：</span> <span class="post-comments-count valine-comment-count" data-xid="/2021/03/05/Freemarker%E5%AD%A6%E4%B9%A0/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2021/03/05/Freemarker%E5%AD%A6%E4%B9%A0/" class="leancloud_visitors" data-flag-title="Freemarker学习">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数：</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-symbolscount">
              

              


              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">56 分钟</span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="Freemarker学习"><a href="#Freemarker学习" class="headerlink" title="Freemarker学习"></a>Freemarker学习</h1><p>[toc]</p>
<blockquote>
<p>注意点：</p>
<p>1、Freemarker得注释是&lt;#–注释的内容–&gt;</p>
<p>2、Freemarker的标签必须完整，否则报错、失效</p>
</blockquote>
<h2 id="一、如何显示数据语法"><a href="#一、如何显示数据语法" class="headerlink" title="一、如何显示数据语法"></a>一、如何显示数据语法</h2><figure class="highlight tcl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">$&#123;num&#125;  # num八大基础类型</span><br><span class="line">$&#123;emp.name&#125;  # obj是对象，并且要满足javaBean的规范，以及该类要以public修饰，否则无法获取其属性</span><br><span class="line">$&#123;emp.date ? <span class="keyword">string</span>（'yyyy -MM-dd'）&#125;   # 日期输出 </span><br><span class="line"><span class="comment"># list遍历，item_has_next返回true / false，需要以string返回，否则报错</span></span><br><span class="line">&lt;#<span class="keyword">list</span> <span class="keyword">list</span> as item&gt;</span><br><span class="line">    &lt;div&gt;对象：$&#123;item&#125;, 索引：$&#123;item_index&#125;，是否有下一个：$&#123;item_has_next ? <span class="keyword">string</span>&#125;&lt;/div&gt;</span><br><span class="line">&lt;/#<span class="keyword">list</span>&gt;</span><br><span class="line"><span class="comment"># map遍历</span></span><br><span class="line">&lt;#<span class="keyword">list</span> map?keys as key&gt;</span><br><span class="line">	&lt;div&gt;键：$&#123;key&#125; 键值：$&#123;map[key]&#125;, 索引：$&#123;key_index&#125;，是否有下一个：$&#123;key_has_next ? <span class="keyword">string</span>&#125;&lt;/div&gt;</span><br><span class="line">&lt;/#<span class="keyword">list</span>&gt;</span><br></pre></td></tr></table></figure>

<h2 id="二、基础语法"><a href="#二、基础语法" class="headerlink" title="二、基础语法"></a>二、基础语法</h2><figure class="highlight elixir"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 变量存在，输出该变量，否则不输出</span></span><br><span class="line"><span class="variable">$&#123;</span>emp.name ? if_exists&#125;  </span><br><span class="line"><span class="variable">$&#123;</span>emp.name ! &#125;</span><br><span class="line"><span class="comment"># 变量不存在，取默认值xxx</span></span><br><span class="line"><span class="variable">$&#123;</span>emp.name ? default(<span class="string">"xxx"</span>)&#125;</span><br><span class="line"><span class="variable">$&#123;</span>emp.name ! <span class="string">"xxx"</span>&#125; </span><br><span class="line"></span><br><span class="line"><span class="variable">$&#123;</span><span class="string">"123&lt;br&gt;456"</span> ? html&#125;    　<span class="comment"># 对字符串进行HTML编码，对html中特殊字符进行转义，即网页显示该字符串内容</span></span><br><span class="line"><span class="variable">$&#123;</span><span class="string">"str"</span> ? cap_first&#125;    　　<span class="comment"># 使字符串第一个字母大写</span></span><br><span class="line"><span class="variable">$&#123;</span><span class="string">"str"</span> ? uncap_first&#125;    　　<span class="comment"># 使字符串第一个字母大写</span></span><br><span class="line"><span class="variable">$&#123;</span><span class="string">"Str"</span> ? lower_case&#125;       <span class="comment"># 将字符串转换成小写</span></span><br><span class="line"><span class="variable">$&#123;</span><span class="string">"Str"</span> ? upper_case&#125;       <span class="comment"># 将字符串转换成大写</span></span><br><span class="line"><span class="variable">$&#123;</span><span class="string">" str "</span> ? trim&#125;           <span class="comment"># 去掉字符串前后的空白字符</span></span><br><span class="line"><span class="variable">$&#123;</span>str ? contains(<span class="string">"xx"</span>) ? string&#125;  <span class="comment"># 字符串是否包含"xxx",返回"true"或"false"</span></span><br><span class="line"><span class="variable">$&#123;</span><span class="string">"你好 $&#123;emp.name !&#125;"</span>&#125;    <span class="comment"># 输出你好+变量名  </span></span><br><span class="line"><span class="variable">$&#123;</span><span class="string">"你好 "</span> + emp.name !&#125;        <span class="comment"># 使用+号来连接，输出你好+变量名</span></span><br><span class="line"><span class="variable">$&#123;</span>emp ? length&#125;      <span class="comment"># 字符串的长度</span></span><br><span class="line"><span class="variable">$&#123;</span>str ? index_of（<span class="string">"x"</span>）&#125;   <span class="comment"># 字符串对应"x"所在位置</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 截取子串</span></span><br><span class="line">&lt;<span class="comment">#assign str ="abcdefghijklmn"/&gt;</span></span><br><span class="line"><span class="variable">$&#123;</span>str ? substring(0 , <span class="number">4</span>)&#125;   <span class="comment"># 1、截取第0位到第3位，输出abcd</span></span><br><span class="line"><span class="variable">$&#123;</span>str[0]&#125; <span class="variable">$&#123;</span>str[<span class="number">4</span>]&#125;   <span class="comment"># 2、截取第0位和第4位结果是ae</span></span><br><span class="line"><span class="variable">$&#123;</span>str[<span class="number">1</span>..<span class="number">4</span>]&#125;         <span class="comment"># 3、截取第1位到第4位结果是bcde</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># split分割字符串</span></span><br><span class="line">&lt;<span class="comment">#list "a|b|c" ? split("|") as item&gt;</span></span><br><span class="line">	<span class="variable">$&#123;</span>item&#125;</span><br><span class="line">&lt;<span class="regexp">/#list&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="三、数字语法"><a href="#三、数字语法" class="headerlink" title="三、数字语法"></a>三、数字语法</h2><figure class="highlight gml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">&lt;#assign <span class="symbol">x</span> = <span class="number">2.582</span> /&gt;</span><br><span class="line">$&#123;<span class="symbol">x</span> ? <span class="built_in">string</span>.number&#125;  # 数字 <span class="number">2.582</span></span><br><span class="line">$&#123;<span class="symbol">x</span> ? <span class="built_in">string</span>.currency&#125;  # 货币 ￥<span class="number">2.58</span>  小数点<span class="number">2</span>位</span><br><span class="line">$&#123;<span class="symbol">x</span> ? <span class="built_in">string</span>.percent&#125;  # 百分号 <span class="number">258</span>%  无小数点</span><br><span class="line">$&#123;<span class="symbol">x</span> ? int&#125;  # 整型<span class="number">2</span></span><br><span class="line"></span><br><span class="line"># 数字格式化插值可采用＃&#123;expr; format&#125;形式来格式化数字，其中格式可以是</span><br><span class="line"># mX：小数部分最小X位</span><br><span class="line"># MX：小数部分最大X位</span><br><span class="line">&lt;#assign <span class="symbol">x</span> = <span class="number">2.582</span> /&gt;</span><br><span class="line">&lt;#assign <span class="symbol">y</span> = <span class="number">4</span> /&gt; </span><br><span class="line">&#123;<span class="symbol">x</span>; M2&#125; <span class="comment">//输出2.58 </span></span><br><span class="line">&#123;<span class="symbol">y</span>; M2&#125; <span class="comment">//输出4 </span></span><br><span class="line">&#123;<span class="symbol">x</span>; m2&#125; <span class="comment">//输出2.58 </span></span><br><span class="line">&#123;Y; m2&#125; <span class="comment">//输出4.0</span></span><br><span class="line">&#123;<span class="symbol">x</span>; m1M2&#125; <span class="comment">//输出2.58 </span></span><br><span class="line">&#123;<span class="symbol">x</span>; m1M2&#125; <span class="comment">//输出4.0</span></span><br></pre></td></tr></table></figure>

<h2 id="四、运算算符"><a href="#四、运算算符" class="headerlink" title="四、运算算符"></a>四、运算算符</h2><figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">表达式中支持的比较运算符符如下几个：</span><br><span class="line">=或==：判断两个值是否相等。</span><br><span class="line">！=：判断两个值是否不等。</span><br><span class="line">&gt; 或 gt：判断左边值是否大于右边值</span><br><span class="line">&lt;= 或 lte：判断左边值是否小于等于右边值</span><br><span class="line"></span><br><span class="line">算数运算符</span><br><span class="line">加减乘除：+, -, *, /, ％</span><br><span class="line">注意：</span><br><span class="line">（<span class="number">1</span>）运算符两边必须是数字</span><br><span class="line">（<span class="number">2</span>）使用+运算符时，如果一边是数字，一边是字符串，就会自动将数字转换为字符串再连接，</span><br><span class="line">     如：$ &#123;<span class="number">3</span> +“<span class="number">5</span>”&#125;，结果是：<span class="number">35</span></span><br><span class="line">     </span><br><span class="line">逻辑运算符</span><br><span class="line">逻辑与：&amp;&amp; </span><br><span class="line">逻辑或：|| </span><br><span class="line">逻辑非：！</span><br><span class="line">逻辑运算符只能作用于布尔值，否则将产生错误</span><br><span class="line"></span><br><span class="line">运算符优先级如下（由高到低排列）</span><br><span class="line"><span class="number">1</span>、一元运算符：！</span><br><span class="line"><span class="number">2</span>、内建函数：</span><br><span class="line"><span class="number">3</span>、乘除法：*，/，％</span><br><span class="line"><span class="number">4</span>、加减法： - ，+ </span><br><span class="line"><span class="number">5</span>、比较：&gt;，&lt;，&gt; =，&lt;=（lt，lte，gt，gte）</span><br><span class="line"><span class="number">6</span>、相等：==，=， ！= </span><br><span class="line"><span class="number">7</span>、逻辑与：&amp;&amp; </span><br><span class="line"><span class="number">8</span>、逻辑或：|| </span><br><span class="line"><span class="number">9</span>、数字范围：.. 实际上，我们在开发过程中应该使用括号来严格区分，这样的可读性好，出错少</span><br></pre></td></tr></table></figure>

<h2 id="五、条件判断"><a href="#五、条件判断" class="headerlink" title="五、条件判断"></a>五、条件判断</h2><figure class="highlight jboss-cli"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> else逻辑判断</span><br><span class="line"><span class="comment"># 示例中conditioinN, N位序号。若其中不为空则执行该条件语句</span></span><br><span class="line">&lt;<span class="comment">#if condition1&gt;</span></span><br><span class="line"><span class="string">...</span></span><br><span class="line">&lt;<span class="comment">#elseif condition2&gt;</span></span><br><span class="line"><span class="string">...</span></span><br><span class="line">&lt;<span class="comment">#elseif condition3&gt;</span></span><br><span class="line"><span class="string">...</span></span><br><span class="line">&lt;<span class="comment">#else&gt;</span></span><br><span class="line"><span class="string">...</span></span><br><span class="line">&lt;/<span class="comment">#if&gt;</span></span><br><span class="line"><span class="comment"># 注意点：$&#123;..&#125;只能用于文本部分,不能用于表达式</span></span><br><span class="line">比如：</span><br><span class="line">&lt;<span class="comment">#if $&#123;isBig&#125;&gt;Wow!&lt;/#if&gt;   # 错误</span></span><br><span class="line">&lt;<span class="comment">#if isBig&gt;Wow!&lt;/#if&gt; #正确</span></span><br><span class="line"></span><br><span class="line">switch</span><br><span class="line"><span class="comment"># 跟java的switch一样，注意break，若无break，则执行后不跳出，而是直接执行下面的语句</span></span><br><span class="line">&lt;<span class="comment">#switch value&gt; </span></span><br><span class="line">&lt;<span class="comment">#case refValue1&gt; </span></span><br><span class="line"><span class="string">....</span></span><br><span class="line">&lt;<span class="comment">#break&gt; </span></span><br><span class="line">&lt;<span class="comment">#case refValue2&gt; </span></span><br><span class="line"><span class="string">....</span></span><br><span class="line">&lt;<span class="comment">#break&gt; </span></span><br><span class="line">&lt;<span class="comment">#case refValueN&gt; </span></span><br><span class="line"><span class="string">....</span></span><br><span class="line">&lt;<span class="comment">#break&gt; </span></span><br><span class="line">&lt;<span class="comment">#default&gt; </span></span><br><span class="line"><span class="string">....</span> </span><br><span class="line">&lt;/<span class="comment">#switch&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="六、支持转义字符"><a href="#六、支持转义字符" class="headerlink" title="六、支持转义字符"></a>六、支持转义字符</h2><figure class="highlight livescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">\"</span> ：双引号(u0022)</span><br><span class="line"><span class="string">\'</span> ：单引号(u0027)</span><br><span class="line"><span class="string">\\</span> ：反斜杠(u005C)</span><br><span class="line"><span class="string">\n</span> ：换行(u000A)</span><br><span class="line"><span class="string">\r</span> ：回车(u000D)</span><br><span class="line"><span class="string">\t</span> ：Tab(u0009)</span><br><span class="line"><span class="string">\b</span> ：退格键(u0008)</span><br><span class="line"><span class="string">\f</span> ：Form feed(u000C)</span><br><span class="line"><span class="string">\l</span> ：&lt;</span><br><span class="line"><span class="string">\g</span> ：&gt;</span><br><span class="line"><span class="string">\a</span> ：&amp;</span><br><span class="line"><span class="string">\&#123;</span> ：&#123;</span><br><span class="line"><span class="string">\xCode</span> ：直接通过<span class="number">4</span>位的<span class="number">16</span>进制数来指定Unicode码,输出该unicode码对应的字符.</span><br><span class="line"></span><br><span class="line">如果某段文本中包含大量的特殊符号,FreeMarker提供了另一种特殊格式:可以在指定字符串内容的引号前增加r标记,在r标记后的文件将会直接输出.看如下代码:</span><br><span class="line">$&#123;r<span class="string">"$&#123;foo&#125;"</span>&#125; <span class="regexp">// 输出 $&#123;foo&#125;</span></span><br><span class="line"><span class="regexp">$&#123;r"C:/foo/bar"&#125; //</span> 输出 C:/foo/bar</span><br></pre></td></tr></table></figure>

<h2 id="七、include指令"><a href="#七、include指令" class="headerlink" title="七、include指令"></a>七、include指令</h2><figure class="highlight dust"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line"><span class="xml"># include指令的作用类似于JSP的包含指令: 用于导入文件,它可以在模版中插入其他的静态文件,或者是freemarker模版如：宏组件</span></span><br><span class="line"><span class="xml"># 注意点：引入同名的变量时就会被后引入的或者新定义的覆盖.这样就不是很好,因为只想让它们在"My Test Library"命名空间中.就需要用 import代替include了</span></span><br><span class="line"><span class="xml">//父页面ftl</span></span><br><span class="line"><span class="xml"><span class="tag">&lt;<span class="name">html</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">  <span class="tag">&lt;<span class="name">head</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">"content-type"</span> <span class="attr">content</span>=<span class="string">"text/html; charset=UTF-8"</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">  <span class="tag">&lt;/<span class="name">head</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">  <span class="tag">&lt;<span class="name">body</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">     <span class="tag">&lt;<span class="name">#include</span> "/<span class="attr">inc</span>/<span class="attr">top.ftl</span>"/&gt;</span>  </span></span><br><span class="line"><span class="xml">        姓名：$</span><span class="template-variable">&#123;student.studentName&#125;</span><span class="xml">  </span></span><br><span class="line"><span class="xml">        性别：$</span><span class="template-variable">&#123;student.studentSex&#125;</span><span class="xml">  </span></span><br><span class="line"><span class="xml">        年龄：$</span><span class="template-variable">&#123;student.studentAge&#125;</span><span class="xml">  </span></span><br><span class="line"><span class="xml">        生日：$</span><span class="template-variable">&#123;(student.studentBirthday)?string("yyyy-MM-dd")&#125;</span><span class="xml">  </span></span><br><span class="line"><span class="xml">        网站地址：$</span><span class="template-variable">&#123;student.studentAddr&#125;</span><span class="xml">  </span></span><br><span class="line"><span class="xml">        QQ：$</span><span class="template-variable">&#123;student.studentQQ&#125;</span><span class="xml">  </span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;<span class="name">#if</span> <span class="attr">student.studentAge</span> <span class="attr">lt</span> <span class="attr">12</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">             $</span><span class="template-variable">&#123;student.studentName&#125;</span><span class="xml">不是一个初中生  </span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;<span class="name">#elseif</span> <span class="attr">student.studentAge</span> <span class="attr">lt</span> <span class="attr">15</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">             $</span><span class="template-variable">&#123;student.studentName&#125;</span><span class="xml">不是一个高中生  </span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;<span class="name">#elseif</span> <span class="attr">student.studentAge</span> <span class="attr">lt</span> <span class="attr">18</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">             $</span><span class="template-variable">&#123;student.studentName&#125;</span><span class="xml">不是一个大学生  </span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;<span class="name">#else</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">             $</span><span class="template-variable">&#123;student.studentName&#125;</span><span class="xml">是一个大学生  </span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;/<span class="name">#if</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">  <span class="tag">&lt;/<span class="name">body</span>&gt;</span>  </span></span><br><span class="line"><span class="xml"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="xml">//子页面ftl</span></span><br><span class="line"><span class="xml"><span class="tag">&lt;<span class="name">h1</span>&gt;</span>欢迎，进入学生管理系统！<span class="tag">&lt;/<span class="name">h1</span>&gt;</span>  	</span></span><br><span class="line"></span><br><span class="line"><span class="xml">// 结果</span></span><br><span class="line"><span class="xml"><span class="tag">&lt;<span class="name">html</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">  <span class="tag">&lt;<span class="name">head</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">"content-type"</span> <span class="attr">content</span>=<span class="string">"text/html; charset=UTF-8"</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">  <span class="tag">&lt;/<span class="name">head</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">  <span class="tag">&lt;<span class="name">body</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">      <span class="tag">&lt;<span class="name">h1</span>&gt;</span>欢迎，进入学生管理系统！<span class="tag">&lt;/<span class="name">h1</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">         姓名：$</span><span class="template-variable">&#123;student.studentName&#125;</span><span class="xml">  </span></span><br><span class="line"><span class="xml">        性别：$</span><span class="template-variable">&#123;student.studentSex&#125;</span><span class="xml">  </span></span><br><span class="line"><span class="xml">        年龄：$</span><span class="template-variable">&#123;student.studentAge&#125;</span><span class="xml">  </span></span><br><span class="line"><span class="xml">        生日：$</span><span class="template-variable">&#123;(student.studentBirthday)?string("yyyy-MM-dd")&#125;</span><span class="xml">  </span></span><br><span class="line"><span class="xml">        网站地址：$</span><span class="template-variable">&#123;student.studentAddr&#125;</span><span class="xml">  </span></span><br><span class="line"><span class="xml">        QQ：$</span><span class="template-variable">&#123;student.studentQQ&#125;</span><span class="xml">  </span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;<span class="name">#if</span> <span class="attr">student.studentAge</span> <span class="attr">lt</span> <span class="attr">12</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">             $</span><span class="template-variable">&#123;student.studentName&#125;</span><span class="xml">不是一个初中生  </span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;<span class="name">#elseif</span> <span class="attr">student.studentAge</span> <span class="attr">lt</span> <span class="attr">15</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">             $</span><span class="template-variable">&#123;student.studentName&#125;</span><span class="xml">不是一个高中生  </span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;<span class="name">#elseif</span> <span class="attr">student.studentAge</span> <span class="attr">lt</span> <span class="attr">18</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">             $</span><span class="template-variable">&#123;student.studentName&#125;</span><span class="xml">不是一个大学生  </span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;<span class="name">#else</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">             $</span><span class="template-variable">&#123;student.studentName&#125;</span><span class="xml">是一个大学生  </span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;/<span class="name">#if</span>&gt;</span>  </span></span><br><span class="line"><span class="xml">  <span class="tag">&lt;/<span class="name">body</span>&gt;</span>  </span></span><br><span class="line"><span class="xml"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span></span><br></pre></td></tr></table></figure>

<h2 id="八、import指令"><a href="#八、import指令" class="headerlink" title="八、import指令"></a>八、import指令</h2><figure class="highlight crystal"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">/<span class="regexp">/ 类似于jsp里的import：它导入文件，然后就可以在当前文件里使用被导入文件里的宏组件。除了不能像include一样导入静态文件外，其他都一样。为防止出现覆盖问题，把其放入另一个空间中。</span></span><br><span class="line"><span class="regexp"># mylib.ftl</span></span><br><span class="line"><span class="regexp">&lt;#macro copyright date&gt;   </span></span><br><span class="line"><span class="regexp">	&lt;p&gt;Copyright (C) $&#123;date&#125; Julia Smith. All rights reserved.   </span></span><br><span class="line"><span class="regexp">&lt;/</span><span class="comment">#macro&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># common.ftl</span></span><br><span class="line">&lt;<span class="comment">#import "/libs/mylib.ftl" as my&gt;</span></span><br><span class="line">&lt;@my.copyright date=<span class="string">"1999-2002"</span>/&gt;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 结果</span></span><br><span class="line">&lt;p&gt;Copyright (C) <span class="number">1999</span>-<span class="number">2002</span> Julia Smith. All rights reserved.   </span><br><span class="line"></span><br><span class="line">/<span class="regexp">/ 上面的代码将导入/lib</span><span class="regexp">/common.ftl模板文件中的所有变量,交将这些变量放置在一个名为com的Map对象中，"my"在freemarker里被称作namespace，防止同一变量被覆盖</span></span><br></pre></td></tr></table></figure>

<h2 id="九、macro宏指令"><a href="#九、macro宏指令" class="headerlink" title="九、macro宏指令"></a>九、macro宏指令</h2><figure class="highlight stata"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">&lt;#-- 定义宏 --&gt;</span><br><span class="line"># <span class="keyword">test</span>是自定义标签名，并且注意自定义标签名会影响同名变量</span><br><span class="line">&lt;#<span class="keyword">macro</span> <span class="keyword">test</span> foo bar=<span class="string">"Bar"</span> baaz=-1&gt; </span><br><span class="line">　　Text: <span class="variable">$&#123;foo&#125;</span>, <span class="variable">$&#123;bar&#125;</span>, <span class="variable">$&#123;baaz&#125;</span></span><br><span class="line">&lt;/#<span class="keyword">macro</span>&gt;</span><br><span class="line"></span><br><span class="line">&lt;#-- 使用宏 --&gt;</span><br><span class="line">&lt;@<span class="keyword">test</span> foo=<span class="string">"a"</span> bar=<span class="string">"b"</span> baaz=5*5/&gt;  <span class="comment">// 输出：Text: a, b, 25</span></span><br><span class="line">&lt;@<span class="keyword">test</span> foo=<span class="string">"a"</span> bar=<span class="string">"b"</span>/&gt;    　　　　<span class="comment">// 输出：Text: a, b, -1</span></span><br><span class="line">&lt;@<span class="keyword">test</span> foo=<span class="string">"a"</span> baaz=5*5-2/&gt; 　　　　<span class="comment">// 输出：Text: a, Bar, 23</span></span><br><span class="line">&lt;@<span class="keyword">test</span> foo=<span class="string">"a"</span>/&gt;                   <span class="comment">// 输出：Text: a, Bar, -1</span></span><br><span class="line"></span><br><span class="line">&lt;#-- 定义一个循环输出的宏 --&gt;</span><br><span class="line">&lt;#<span class="keyword">macro</span> <span class="keyword">list</span> title items&gt; </span><br><span class="line">　　<span class="variable">$&#123;title&#125;</span></span><br><span class="line">　　&lt;#<span class="keyword">list</span> items <span class="keyword">as</span> x&gt;</span><br><span class="line">　　　　<span class="variable">$&#123;x&#125;</span></span><br><span class="line">　　&lt;/#<span class="keyword">list</span>&gt; </span><br><span class="line">&lt;/#<span class="keyword">macro</span>&gt; </span><br><span class="line"></span><br><span class="line">&lt;#-- 使用宏 --&gt;</span><br><span class="line">&lt;@<span class="keyword">list</span> items=[<span class="string">"mouse"</span>, <span class="string">"elephant"</span>, <span class="string">"python"</span>] title=<span class="string">"Animals"</span>/&gt;</span><br></pre></td></tr></table></figure>


      
    </div>

    

    
    
    

    <div>
        
            
<div class="my_post_copyright">
  <script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>
  
  <!-- JS库 sweetalert 可修改路径 -->
  <script type="text/javascript" src="http://jslibs.wuxubj.cn/sweetalert_mini/jquery-1.7.1.min.js"></script>
  <script src="http://jslibs.wuxubj.cn/sweetalert_mini/sweetalert.min.js"></script>
  <link rel="stylesheet" type="text/css" href="http://jslibs.wuxubj.cn/sweetalert_mini/sweetalert.mini.css">

  <p><span>本文标题:</span>Freemarker学习</a></p>
  <p><span>文章作者:</span>Deschen</a></p>
  <p><span>发布时间:</span>2021年03月05日 - 18:42:58</p>
  <p><span>最后更新:</span>2021年03月18日 - 00:29:59</p>
  <p><span>原始链接:</span><a href="/2021/03/05/Freemarker%E5%AD%A6%E4%B9%A0/" title="Freemarker学习">https://chaasuc.github.io/2021/03/05/Freemarker%E5%AD%A6%E4%B9%A0/</a>
    <span class="copy-path"  title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="https://chaasuc.github.io/2021/03/05/Freemarker%E5%AD%A6%E4%B9%A0/"  aria-label="复制成功！"></i></span>
  </p>
  <p><span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
</div>
<script> 
    var clipboard = new Clipboard('.fa-clipboard');
    clipboard.on('success', $(function(){
      $(".fa-clipboard").click(function(){
        swal({   
          title: "",   
          text: '复制成功',   
          html: false,
          timer: 500,   
          showConfirmButton: false
        });
      });
    }));  
</script>


        
    </div>

    
      <div>
          <div id="wechat_subscriber" style="display: block; padding: 10px 0; margin: 20px auto; width: 100%; text-align: center">
    <img id="wechat_subscriber_qcode" src="/uploads/%E5%BE%AE%E4%BF%A1%E5%A4%B4%E5%83%8F.jpg" alt="Deschen wechat" style="width: 200px; max-width: 100%;"/>
    <div>微信公众号还没弄好，先放上二维码吧！</div>
</div>

      </div>
    


    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>如果文章能帮助到你，希望继续支持我</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="Deschen 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="Deschen 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Freemarker/" rel="tag"># Freemarker</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2021/02/28/Yapi%E7%9A%84%E9%83%A8%E7%BD%B2%E5%92%8C%E4%BD%BF%E7%94%A8/" rel="next" title="Yapi 的部署和使用">
                <i class="fa fa-chevron-left"></i> Yapi 的部署和使用
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2021/08/10/%E9%9D%A2%E8%AF%95%E9%A2%98-MySQL/" rel="prev" title="面试题-MySQL">
                面试题-MySQL <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
      <div id="sidebar-dimmer"></div>
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/wolf_128.png"
                alt="Deschen" />
            
              <p class="site-author-name" itemprop="name">Deschen</p>
              <p class="site-description motion-element" itemprop="description">机遇只会给有准备的人</p>
          </div>

          
            <nav class="site-state motion-element">
              
              <!-- todo 日志路径错误bug  
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">67</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>-->
                <!--临时方法-->
                <div class="site-state-item site-state-posts">
                  <a href="/archives/index.html">
                    <span class="site-state-item-count">67</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">19</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">36</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  <a href="https://github.com/ChaASuc" target="_blank" title="GitHub"><i class="fa fa-fw fa-github"></i>GitHub</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://blog.csdn.net/weixin_39147889" target="_blank" title="CSDN"><i class="fa fa-fw fa-crosshairs"></i>CSDN</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="deschen151@163.com" target="_blank" title="E-Mail"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="adsw2042340074" target="_blank" title="WECHAT"><i class="fa fa-fw fa-wechat"></i>WECHAT</a>
                  
                </span>
              
            </div>
          

          
          

          
          

          
            
          
          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Freemarker学习"><span class="nav-number">1.</span> <span class="nav-text">Freemarker学习</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、如何显示数据语法"><span class="nav-number">1.1.</span> <span class="nav-text">一、如何显示数据语法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、基础语法"><span class="nav-number">1.2.</span> <span class="nav-text">二、基础语法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#三、数字语法"><span class="nav-number">1.3.</span> <span class="nav-text">三、数字语法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#四、运算算符"><span class="nav-number">1.4.</span> <span class="nav-text">四、运算算符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#五、条件判断"><span class="nav-number">1.5.</span> <span class="nav-text">五、条件判断</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#六、支持转义字符"><span class="nav-number">1.6.</span> <span class="nav-text">六、支持转义字符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#七、include指令"><span class="nav-number">1.7.</span> <span class="nav-text">七、include指令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#八、import指令"><span class="nav-number">1.8.</span> <span class="nav-text">八、import指令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#九、macro宏指令"><span class="nav-number">1.9.</span> <span class="nav-text">九、macro宏指令</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright"> &copy; 2019 – <span itemprop="copyrightYear">2024</span>
  <span class="with-love" id="animate">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">deschen</span>
  
  <div class="post-symbolscount">
    

    



  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    
    <span title="站点阅读时长">6:08</span>
  
</div>






<a href="https://beian.miit.gov.cn/" target="_blank" rel="noopener">粤ICP备19118852号</a> 




        








        
      </div>
    </footer>

    

    
	
    

    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>














  
    
      
  
  <script type="text/javascript" color='0,0,255' opacity='0.5' zIndex='-1' count='99' src="/lib/canvas-nest/canvas-nest.min.js"></script>













  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=6.5.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.5.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=6.5.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=6.5.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.5.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=6.5.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.5.0"></script>



  



  








  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  
  
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(function (item) {
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: 'kLXtQMuxJVoheKykjMyEuj77-9Nh9j0Va',
        appKey: '5wR39MUwQHTYj03j6lJgkqIY',
        placeholder: '请发表有价值的评论，共同维护学习氛围',
        avatar:'mm',
        meta:guest,
        pageSize:'10' || 10,
        visitor: false
    });
  </script>



  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "./public/search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
  <script>
    
    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();

      Counter('get', '/classes/Counter', { where: JSON.stringify({ url }) })
        .done(function ({ results }) {
          if (results.length > 0) {
            var counter = results[0];
            
            Counter('put', `/classes/Counter/${counter.objectId}`, JSON.stringify({ time: { "__op":"Increment", "amount":1 } }))
            
            .done(function () {
                  var $element = $(document.getElementById(url));
                  $element.find('.leancloud-visitors-count').text(counter.time + 1);
            })
            
            .fail(function ({ responseJSON }) {
                console.log('Failed to save Visitor num, with error message: ' + responseJSON.error);
            })
          } else {
            
              Counter('post', '/classes/Counter', JSON.stringify({ title: title, url: url, time: 1}))
                .done(function () {
                  var $element = $(document.getElementById(url));
                  $element.find('.leancloud-visitors-count').text(1);
                })
                .fail(function () {
                  console.log('Failed to create');
                });
            
          }
        })
      .fail(function ({ responseJSON }) {
        console.log('LeanCloud Counter Error:' + responseJSON.code + " " + responseJSON.error);
      });
    }
    

    $(function() {
      $.get('https://app-router.leancloud.cn/2/route?appId=' + "kLXtQMuxJVoheKykjMyEuj77-9Nh9j0Va")
        .done(function ({ api_server }) {
          var Counter = function (method, url, data) {
            return $.ajax({
              method: method,
              url: `https://${api_server}/1.1${url}`,
              headers: {
                'X-LC-Id': "kLXtQMuxJVoheKykjMyEuj77-9Nh9j0Va",
                'X-LC-Key': "5wR39MUwQHTYj03j6lJgkqIY",
                'Content-Type': 'application/json',
              },
              data: data,
            });
          };
          
          addCount(Counter);
          
        })
    });
  </script>



  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  

  

  
  

  

  

  

  

  
  <style>
    .copy-btn {
      display: inline-block;
      padding: 6px 12px;
      font-size: 13px;
      font-weight: 700;
      line-height: 20px;
      color: #333;
      white-space: nowrap;
      vertical-align: middle;
      cursor: pointer;
      background-color: #eee;
      background-image: linear-gradient(#fcfcfc, #eee);
      border: 1px solid #d5d5d5;
      border-radius: 3px;
      user-select: none;
      outline: 0;
    }

    .highlight-wrap .copy-btn {
      transition: opacity .3s ease-in-out;
      opacity: 0;
      padding: 2px 6px;
      position: absolute;
      right: 4px;
      top: 8px;
    }

    .highlight-wrap:hover .copy-btn,
    .highlight-wrap .copy-btn:focus {
      opacity: 1
    }

    .highlight-wrap {
      position: relative;
    }
  </style>
  <script>
    $('.highlight').each(function (i, e) {
      var $wrap = $('<div>').addClass('highlight-wrap')
      $(e).after($wrap)
      $wrap.append($('<button>').addClass('copy-btn').append('复制').on('click', function (e) {
        var code = $(this).parent().find('.code').find('.line').map(function (i, e) {
          return $(e).text()
        }).toArray().join('\n')
        var ta = document.createElement('textarea')
        document.body.appendChild(ta)
        ta.style.position = 'absolute'
        ta.style.top = '0px'
        ta.style.left = '0px'
        ta.value = code
        ta.select()
        ta.focus()
        var result = document.execCommand('copy')
        document.body.removeChild(ta)
        
          if(result)$(this).text('复制成功')
          else $(this).text('复制失败')
        
        $(this).blur()
      })).on('mouseleave', function (e) {
        var $b = $(this).find('.copy-btn')
        setTimeout(function () {
          $b.text('复制')
        }, 300)
      }).append(e)
    })
  </script>


  
   <script async src="/js/src/click-fireworks.js"></script>
  


<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"model":{"jsonPath":"/live2dw/assets/hijiki.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":false},"log":false});</script></body>
</html>
